package com.test1224;

public class Test10 {
    public static void main(String[] args) {
        // 互换数组arr中最大值和最小值的位置
        int[] arr = {6, 1, 7, 4, 3};
        int max = arr[0];
        int min = arr[0];
        int maxIndex = 0;
        int minIndex = 0;
        for(int i=1;i<arr.length;i++){
            if(max<arr[i]){
                max=arr[i];
                maxIndex =i;
            }
        }
        for(int i=1;i<arr.length;i++){
            if(min>arr[i]){
                min=arr[i];
                minIndex =i;
            }
        }
        int temp = arr[maxIndex];
        arr[maxIndex] = arr[minIndex];
        arr[minIndex] = temp;
        for(int history:arr){
            System.out.print(history+" ");
        }


    }
}
